//package com.csw.springbootquartz.task.scheduletaskTest.a1;
//
//import com.csw.springbootquartz.entity.SchedulerJob;
//import com.csw.springbootquartz.service.SchedulerJobService;
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.quartz.CronScheduleBuilder;
//import org.quartz.TriggerBuilder;
//import org.springframework.scheduling.Trigger;
//import org.springframework.scheduling.TriggerContext;
//import org.springframework.scheduling.annotation.SchedulingConfigurer;
//import org.springframework.scheduling.config.CronTask;
//import org.springframework.scheduling.config.ScheduledTaskRegistrar;
//import org.springframework.scheduling.config.TriggerTask;
//import org.springframework.scheduling.support.CronTrigger;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDateTime;
//import java.util.Date;
//import java.util.List;
//import java.util.Set;
//
///**
// * 定时任务
// *
// * @author wl
// * @date 2022/3/22
// */
//@Data
//@Slf4j
//@Component
////@PropertySource("classpath:/task-config.ini")
//public class ScheduleTask implements SchedulingConfigurer {
//    Trigger newTrigger = null;
//
//    //    @Value("${printTime.cron}")
////    private String cron;
//    private static SchedulerJobService schedulerJobService;
//
//    public ScheduleTask(SchedulerJobService schedulerJobService) {
//        ScheduleTask.schedulerJobService = schedulerJobService;
//    }
//
//    //表达式
//    private String cron;
//    //开关
//    private String running;
//
//    @Override
//    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
//        SchedulerJob schedulerJob = schedulerJobService.findByid("a823f7054ac640c7a4ed0fef4e994c06");
//        log.error("查询一次数据库{}", this.getClass());
//        // 动态使用cron表达式设置循环间隔
//        if (StringUtils.isEmpty(cron)) {
//            cron = schedulerJob.getCron();
//            newTrigger=new CronTrigger(cron);
//        }
//        if (StringUtils.isEmpty(running)) {
//            running = schedulerJob.getRunning();
//        }
//
//
//        taskRegistrar.addTriggerTask(new Runnable() {
//            @Override
//            public void run() {
//                if ("on".equals(running)) {
//                    //doSomething
//                    log.error("进入代码Current time： {}", LocalDateTime.now());
//                }
//            }
//
//        },newTrigger
////                new Trigger() {
////            @Override
////            public Date nextExecutionTime(TriggerContext triggerContext) {
////
////                //更改会在下次检查的时候才生效，缺陷，如果设置错误，只能重启
////
////                //log.info("进入设置cron");
////                // 使用CronTrigger触发器，可动态修改cron表达式来操作循环规则
////
////                CronTrigger cronTrigger = new CronTrigger(cron);
////                Date nextExecutionTime = cronTrigger.nextExecutionTime(triggerContext);
////                return nextExecutionTime;
////            }
////        }
//        );
//
////        taskRegistrar.addCronTask(new CronTask(new Runnable() {
////            @Override
////            public void run() {
////                if ("on".equals(running)) {
////                    //doSomething
////                    log.info("进入代码Current time： {}", LocalDateTime.now());
////                }
////            }
////        }, cron));
//    }
//}
